
using UnityEngine;

namespace Enemy
{
    public class HitState : IState
    {
        public HitState(FSM manager)
        {
            this.manager = manager;
            this.parameter = manager.parameter;
        }

        public override void OnEnter()
        {
            AudioManager.Instance.PlaySFX("小怪史莱姆被击中");
            parameter.animator.Play("Hit");
            // parameter.rb.velocity = Vector2.zero;
        }

        public override void OnUpdate()
        {
            // 转换到死亡状态
            if (parameter.isDead)
            {
                manager.TransitionState(StateType.Death);
            }

            // 如果动画播放进度超过95%，重新寻找玩家目标并转换到追逐状态
            if (parameter.animatorStateInfo.normalizedTime >= 0.95f)
            {
                // parameter.target = GameObject.FindWithTag("Player").transform;    // 寻找标签为Player的目标

                manager.TransitionState(StateType.Chase);    // 转换到追逐状态
            }
        }

        public override void OnFixedUpdate() {}

        public override void OnExit()
        {
            parameter.isHurt = false;    // 离开状态时重置受击标志
        }
    }
}
